/***************************************************
	
	SLICK ADMIN PANEL - 13 COLOURS
	
	Created : 10/04/2011
	Designer : Matthew Corner  (QwibbleDesigns)
	Coder : Matthew Corner (QwibbleDesigns)
	Website : http://www.qwibbledesigns.co.uk/
	
****************************************************/

/***************************
	  CUSTOM JQUERY
***************************/
	
$(document).ready(function() {
	
	
	
	// Close notifications (fade and slideup)
		
		$(".notification a.close").click(function () {
			$(this).parent().fadeTo(400, 0, function () {
				$(this).slideUp(200);
			});
			return false;
		});
		
	// Table Actions Links
	
		$("ul.actions li a").hide().children('img').fadeTo(0,0.7);
		$("table#data tr td").hover(
			function () {
				$(this).parents('tr').find("ul.actions li a").show();
			},
			function () {
				$(this).parents('tr').find("ul.actions li a").hide();
			}
		);
		$("ul.actions li a img").hover(
			function () {
				$(this).fadeTo(0,1.0)
			},
			function () {
				$(this).fadeTo(0,0.7)
			}
		)
		
	// Image Gallery hover links
	
		$(".image_links a").fadeTo(0, 0.7);
		$(".image_links").hide();
		$("ul#images li").hover(
			function () {
				$(this).children(".image_links").show();
			},
			function (){
				$(this).children(".image_links").hide();	
			}
		);
		
		$(".image_links li a").hover(
			function () {
				$(this).fadeTo(0, 1.0);
			},
			function (){
				$(this).fadeTo(0, 0.7);	
			}
		);
		
	// Visualise Graph's
	
		if ($('table.bar, table.line').length > 0){
			$('table.bar').hide().visualize({type: 'bar', width: '540px', height: '250px'});
			$('table.line').hide().visualize({type: 'line', width: '540px', height: '250px'});
		}


	// Textarea limiter

		if ($('textarea.limit').length > 0){
			$.getScript('js/jquery.limit-1.2.js', function() {
				$('textarea.limit').limit('150','#charsLeft');
			});
		}
		
	// Fire the Uniform Script if checkboxes, radio buttons, or file inputs are found
	
		var applyUniform = function() {
			$.getScript('js/jquery.uniform.min.js', function() {
				$("input:checkbox, input:radio, input:file").uniform();	
				$('input:file').after('<div class="clear"></div>')
        	});
		}
							
		if ($('input:checkbox').length > 0){
			applyUniform();
		}
		else if ($('input:radio').length > 0){
			applyUniform();
		}
		else if ($('input:file').length > 0){
			applyUniform();
		}
		
		
	// Fire Stylish Select plugin if selects are found	
		
		if ($('select').length > 0){
			$.getScript('js/jquery.stylish-select.min.js', function() {
				$('select').sSelect({ddMaxHeight: '200px'});
      		});
		}
		
	// Fire jHtmlArea and ColorpickerMenu plugins if textarea with a class of full is found.
			
		if ($('textarea.full').length > 0){
			$.getScript('js/jHtmlArea-0.7.0.js', function() {
				$.getScript('js/jHtmlArea.ColorPickerMenu-0.7.0.js', function() {
					$("textarea.full").htmlarea({
						toolbar: [
					        ["html"], ["bold", "italic", "underline", "strikethrough", "|", "subscript", "superscript"],
					        ["forecolor", "increasefontsize", "decreasefontsize"],
					        ["orderedlist", "unorderedlist"],
					        ["indent", "outdent"],
					        ["justifyleft", "justifycenter", "justifyright"],
					        ["link", "unlink", "image", "horizontalrule"],
					        ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
					        ["cut", "copy", "paste"]
					    ]
					});
	       		});
	        });
		}
		
	// Check all checkboxes in the table when the header checkbox is selected
	
		$('table#data thead input[type=checkbox]').click(function(){
			var table = $(this).parents('table');
			if($(this).is(':checked')){
				table.find('div.checker span').addClass('checked');
				table.find('input[type=checkbox]').attr('checked', true);
			}
			else if($(this).is(':not(:checked)')){
				table.find('div.checker span').removeClass('checked');
				table.find('input[type=checkbox]').attr('checked', false);
			}
		});
	
	// Content box tabs:

        $('.box .box_content div.tab_content').hide(); 
        $('ul.tabs li a.default').addClass('current'); 
        $('.box_content div.default').show(); 
        $('.box ul.tabs li a').click( 
            function() { 
                $(this).parent().siblings().find("a").removeClass('current'); 
                $(this).addClass('current'); 
                var currentTab = $(this).attr('href'); 
                $(currentTab).siblings().hide(); 
                $(currentTab).show();
                return false; 
            }
        );
	
	// Close boxes
	
		$(".box h2").css({"cursor":"s-resize"});
		$(".box h2").click(
			function ()	{
				$(this).parent().siblings('.box_content').toggle();
				$(this).parents('.box').toggleClass('closed');
				$(this).siblings('ul.tabs, a.link').toggle();
			}
		);
		
	// Fancybox
	
		if($("ul.image_links").length > 0){
			$.getScript('js/jquery.fancybox-1.3.4.pack.js', function() {
				$("ul.image_links a[rel=gallery]").fancybox({
					'overlayColor' : '#333',
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'fade',
					'titlePosition' 	: 'over',
					'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + '/' + currentArray.length + ' - ' + title + '</span>';
					
					}
				});
			});
		}
	
});
